package wiz.client;

import wiz.client.activities.WizActivityMapper;
import wiz.client.activities.entrypoint.EntryPointPlace;
import wiz.client.ui.TransitionPanel;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.web.bindery.event.shared.EventBus;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Wiz implements EntryPoint {

	@Override
	public void onModuleLoad() {
		
		//TODO: GIN
        ClientFactory clientFactory = new ClientFactory();
        EventBus eventBus = clientFactory.getEventBus();
        PlaceController placeController = clientFactory.getPlaceController();

        
        SimplePanel appWidget = new TransitionPanel();
        
        // Start ActivityManager for the main widget with our ActivityMapper
        ActivityMapper activityMapper = new WizActivityMapper(clientFactory);
        ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
        activityManager.setDisplay(appWidget);

        // Start PlaceHistoryHandler with our PlaceHistoryMapper
        PlaceHistoryMapper historyMapper=  clientFactory.getPlaceHistoryMapper();
        PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler.register(placeController, eventBus, new EntryPointPlace());

        RootPanel.get("wizRootPanel").add(appWidget); //$NON-NLS-1$
        // Goes to the place represented on URL else default place
        historyHandler.handleCurrentHistory();
        
        
        
//        Audio createIfSupported = Audio.createIfSupported();
//        if(createIfSupported != null){
//        	RootPanel.get("wizRootPanel").add(createIfSupported);
//            //ok have some fun, register the sound playing event handler
//            clientFactory.getEventBus().addHandler(WizEvent.TYPE, new SoundEventHandler(createIfSupported.getAudioElement()));
//        	
//        }

	}
}
